package win.zxshuo.www.utils;

import java.util.Calendar;
import java.util.Date;

public class TimeUtils {

    public static String compareNowTime(Date toCompare){
        String result = "";

        Long nd = 1000L * 24L * 60L * 60L;// 一天的毫秒数
        Long nh = 1000L * 60L * 60L;// 一小时的毫秒数
        Long nm = 1000L * 60L;// 一分钟的毫秒数
        Long ns = 1000L;// 一秒钟的毫秒数
        Long day = 0L;
        Long hour = 0L;
        Long min = 0L;
        Long sec = 0L;

        Date now = new Date();
        Long diff = toCompare.getTime() - now.getTime();
        String suffix = "前";
        if (diff >0){
            suffix = "后";
        }
        diff = Math.abs(diff);
        day = diff / nd;
        hour = diff / nh;
        min = diff / nm;
        sec = diff / ns;
        if (day > 1){
            return day.toString()+"天"+suffix;
        }
        if (hour >1 ){
            return hour.toString()+"小时"+suffix;
        }
        if (min > 1 ){
            return min.toString() + "分钟"+ suffix;
        }
        return sec.toString() + "秒"+ suffix;
    }



}
